+ 2

Can't we use continue outside loops????

I tried using it outside any loop but it only shows label missing. Is it possible that I can only use continue inside loop?

26th Feb 2018, 12:47 PM
Shrawan Chakradhar
Shrawan Chakradhar - avatar
3 Respuestas
+ 16
we use continue , to skip the statement(s) for some particular cycles , there is no need of continue outside a loop[its better to use if else]
26th Feb 2018, 1:01 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
0
I wanted to build a program where in the end the user will be asked once if he or she want to leave or go back.. and to go back I used continue. What should I use for it then??
26th Feb 2018, 1:50 PM
Shrawan Chakradhar
Shrawan Chakradhar - avatar
0
No, continue can not be used outside loops. A solution for your problem might be: Get a method like questionExit () which returns a boolean value depending on how the user decided. If he wants to leave (if statement here!), you stop your programm or something else. If he doesn't, you either do nothing or go back or something what you want...
26th Feb 2018, 2:58 PM
D B
D B - avatar