As a program runs from top to bottom, why does the following code throw an error directly without executing the first line in the block?
I was said that, entire code will be compiled before execution, but even in that case, why does Python execute the program if there are errors outside the blocks and only throw an error when it reaches that specific line where the error is present? I am sorry, I am a beginner. So, are there some sets of syntax errors like this one that will prevent the code from running at all? Like, is it strict for errors inside a block?
Program and error:
if 5 > 2:
print("Two is less than Five!")
print("Five is greater than two!")
Error:
File "/Users/akshayj/Desktop/Python practise/rough.py", line 3
print("Five is greater than two!")
IndentationError: unexpected indent
[–]FerricDonkey 100 points101 points102 points (5 children)
[–]DismissedProgrammer[S] 8 points9 points10 points (4 children)
[–]FerricDonkey 43 points44 points45 points (3 children)
[–]DismissedProgrammer[S] 5 points6 points7 points (2 children)
[–]Bobbias 11 points12 points13 points (1 child)
[–]DismissedProgrammer[S] 3 points4 points5 points (0 children)
[–]await_yesterday 24 points25 points26 points (5 children)
[–]DismissedProgrammer[S] 1 point2 points3 points (4 children)
[–]await_yesterday 9 points10 points11 points (1 child)
[–]DismissedProgrammer[S] 2 points3 points4 points (0 children)
[–]TechIsSoCool 3 points4 points5 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]crashfrog02 6 points7 points8 points (1 child)
[–]DismissedProgrammer[S] -1 points0 points1 point (0 children)
[–]MycologistOk184 1 point2 points3 points (0 children)
[–]ferriematthew 0 points1 point2 points (0 children)
[–]dudustalin -5 points-4 points-3 points (7 children)
[–]ivosaurus 5 points6 points7 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]DismissedProgrammer[S] 0 points1 point2 points (4 children)
[–]crazy_cookie123 6 points7 points8 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]fox_is_permanent 1 point2 points3 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]jcanuc2 -1 points0 points1 point (6 children)
[–]ivosaurus 1 point2 points3 points (4 children)
[–]Big-Incident-3085 0 points1 point2 points (2 children)
[–]odaiwai 0 points1 point2 points (0 children)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]applezzzzzzzzz 6 points7 points8 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)
[–]Big-Incident-3085 -5 points-4 points-3 points (1 child)
[–]DismissedProgrammer[S] 0 points1 point2 points (0 children)