first=[]
list_1=int(input("Enter the numbers of elements for 1st list = "))
for i in range(list_1):
new = int(input())
first.append(new)
continue
print (first)
second=[]
list_2=int(input("Enter the number of elements in 2nd list= "))
for x in range(list_2):
new_2=int(input())
second.append(new_2)
continue
print(second)
CodePudding user response:
Python is a identation-sensitive language. In your code, print(second)
is within the for
loop but after the continue
keyword.
Because continue
is a flow control operation, it's essentially skipping print(second)
, which is the reason for the error.
CodePudding user response:
Condition to continue is missing so complier found at compile time that last time is unreachable.
Parse 1 compilier Parse 2 compiler
The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
This example skips the value of 4:
Example
for (int i = 0; i < 10; i ) {
if (i == 4) {
continue;
}
System.out.println(i);
}