The other answers are essentially correct. Good SQL code generally requires a different way of thinking than how procedural or object-oriented programmers are used to thinking. SQL is optimized to perform operations on sets of data. Your DELETE FROM table2 WHERE ...
statement is sent to the back-end database, where the database knows how to most efficiently take that statement and perform the operation across the whole set of results at once.
One of the reasons for this is because many large-scale applications have a front-end (user interface), a server that accepts the user requests (e.g.: web server), and a back end database server. It would be in efficient for the SQL code being executed on the web server (where your SQL script may originate from) to have to make single requests to the back end to delete each item in the table in a loop. The messages sent from the web server to the database server would look something like this (pseudo-code messages):
web server -> Find all elements matching criteria -> database
web server <- (return of matching elements) <- database
web server -> Delete element[0] from myTable -> database
web server <- (delete result was ok) <- database
web server -> Delete element[1] from myTable -> database
web server <- (delete result was ok) <- database
....
Whereas, the SQL approach would produce messages back and forth that would look more like:
web server -> Find all elements matching criteria -> database
and delete them.
web server <- (delete result was ok) <- database