Can we use else statement without an if condition in c similar to python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we use else statement without an if condition in c similar to python

29th Oct 2021, 12:58 AM
Mohammad Shama
11 Answers
+ 3
We can write an equivalent if we knew the use case. In python, the else is useful if we are using a while loop as sort of a look up function. If the value we are looking for is not found, we can run an else to maybe notify the user. If it is found, we can break the loop so the else is never run. This is easily done in C by simply using a flag "isFound" or by loading the found entry into a veriable for further work.
30th Oct 2021, 7:56 PM
Kail Galestorm
Kail Galestorm - avatar
+ 5
else in python (except with if...) can be used with: ▪︎for ... loop ▪︎while ... loop ▪︎try ... except ...
30th Oct 2021, 1:36 PM
Lothar
Lothar - avatar
+ 4
Python's while/else and for/else statements are unique to Python. You won't find anything like them in C.
29th Oct 2021, 1:36 AM
Brian
Brian - avatar
+ 3
No, where in python have you seen that?
29th Oct 2021, 1:03 AM
Slick
Slick - avatar
+ 2
In few iterable cases we can run else statement without if after 'for' or after 'while' inorder to indicate the end of iterations
29th Oct 2021, 1:19 AM
Mohammad Shama
+ 1
No, first of all, you have to understand what is where is used else statement, he is use case if boolean result is False, then, in Python or C, then if else is first than if, it would gives a syntax error
29th Oct 2021, 1:03 AM
Katdotbrush
Katdotbrush - avatar
+ 1
I guess the simple answer is no, you can't
29th Oct 2021, 2:10 AM
Rishi
Rishi - avatar
+ 1
Okay thank you all
29th Oct 2021, 8:01 AM
Mohammad Shama
0
In python...
29th Oct 2021, 1:19 AM
Mohammad Shama
0
I don't think so. What cases?
29th Oct 2021, 1:33 AM
Slick
Slick - avatar
0
Thank you Kail for your valuable answere
31st Oct 2021, 4:14 AM
Mohammad Shama