0
0
Blockchain / Solidityprogramming~5 mins

If-else statements in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of an if-else statement?
An if-else statement lets a program choose between two paths: one if a condition is true, and another if it is false.
Click to reveal answer
beginner
How do you write a simple if-else statement in Solidity?
You write it like this:<br>
if (condition) {<br>  // code if true<br>} else {<br>  // code if false<br>}
Click to reveal answer
beginner
What happens if the if condition is false and there is no else block?
The program skips the if block and continues with the code after it, doing nothing inside the if.
Click to reveal answer
intermediate
Can you have multiple conditions checked in an if-else structure?
Yes, by using else if blocks between if and else, you can check many conditions in order.
Click to reveal answer
intermediate
Why are if-else statements important in blockchain smart contracts?
They let contracts make decisions, like checking if a user has enough balance before sending tokens.
Click to reveal answer
What does an if-else statement do in a program?
AChooses between two actions based on a condition
BRepeats code multiple times
CStores data permanently
DDefines a new function
In Solidity, what keyword starts the condition check?
Aif
Bfor
Cwhile
Dswitch
What happens if the if condition is false and there is no else block?
AThe program crashes
BThe if block runs anyway
CThe program skips the if block and continues
DThe else block runs
How can you check multiple conditions in an if-else structure?
AUsing multiple if statements only
BUsing else if blocks
CUsing switch-case only
DUsing loops
Why are if-else statements useful in smart contracts?
ATo store user data
BTo connect to the internet
CTo create new tokens
DTo make decisions based on conditions
Explain how an if-else statement controls the flow of a program.
Think about choosing between two roads based on a sign.
You got /4 concepts.
    Describe a real-life example where an if-else statement would be useful in a blockchain smart contract.
    Imagine sending money only if you have enough.
    You got /4 concepts.