- 1

if commands

Help me im stuck i dont know them and i need them

23rd Sep 2019, 11:13 AM
Cobster21
Cobster21 - avatar
4 Respostas
+ 3
Can you show a code you were struggling with?
23rd Sep 2019, 11:35 AM
Seb TheS
Seb TheS - avatar
+ 2
If statements are used to make a decision between two or more conditions.
23rd Sep 2019, 11:51 AM
Sonic
Sonic - avatar
+ 1
if [condition]: # do something if len("hello") == 5: print("Yes")
23rd Sep 2019, 1:07 PM
Trigger
Trigger - avatar
+ 1
If I reply to your question, I help you find your answer If I press my PC's power button it will turn on If I press the send button, this message will be sent to the comment section. With an if statement, a condition must be true for the code within to execute. If(input = 1) Print "true" Else Print "false" In the above code, when the input becomes 1 the code will print 'true'. It will only ever do this when the input is 1 so if it changes to any other number it prints false. This works even if we remove the else statment If statements are normally used for true/false decisions, they're very similar to switch statements in the way that they work. The only difference between the 2 is their syntax. Else statements can be used if specific code should execute if the condition wasn't met. In the above, if input isn't 1 then it will print false. If you don't include an else statement then the program will evaluate the condition, execute the code if it needs to and then move onto executing the remainder.
25th Sep 2019, 10:19 AM
kc101010