Aptos Move by Example
  • 🚀Getting Started
  • Set-Up
  • Why is Move Secure
    • Move prover
  • Move vs Solidity
    • Resources
    • Parallel Processing
    • Reentrancy attacks
    • Memory management
    • Smart contract verification
    • Compiled language
  • Basic Concepts
    • Move.toml
    • Primary data-types
    • Strings
    • Comments
    • Functions
    • Function Visibilities
    • Control flow and expressions
    • Loops
    • Error
    • Struct and its Abilities
    • Scripts
    • Operations
  • Intermediate Concepts
    • Local variables
    • Constants
    • Signer
    • Vector
    • Address
    • Uses and Aliases
    • Maps
    • Hash functions
    • References
    • Unit test
    • Generics
    • Type Arguments
    • Type Inference
  • Advanced Concepts
    • Global Storage Structure
    • Global Storage Operations
    • Phantom Type Parameters
    • Timestamps
    • Ownership
    • Move coding conventions
    • View functions
    • Aptos account
    • Aptos Coin
    • Aptos Token(Nft)
    • Object
    • Token V2
  • Applications
    • First App
    • ToDoList
    • Voting System
    • Basic Tokens
    • Storage using Generics
    • Company
    • Collection
    • Football Card
    • Staking Module
    • MultiSender Wallet
    • English Auction
    • Dutch Auction
    • Attendance Sheet
    • Polling Contract
    • Lottery Contract
  • Decentralized Finance
    • Simple Swap Protocol Contract
    • Code of Swapping Protocol
  • Hacks
    • Coming soon
  • Hands on tutorials
    • Indexer tutorials
Powered by GitBook
On this page
Edit on GitHub
  1. Basic Concepts

Control flow and expressions

Control flow statement is a statement that results in a choice being made as to which of two or more paths to follow.

Move achieves control flow by using if-else expressions and loops.

If expression:

// syntax for if expression
if(<bool-expression>)
    <expression>
else if(<bool-expression>)
    <expression>
..
..
else 
    <expression>

For all integer types all the values except 0 are considered true.

module my_addrx::IF_ELSE
{
    use std::debug::print;
    use std::string::utf8;
    
    fun control_flow()
    {
        let val:bool = true;
        if(val)
        {
            print(&utf8(b"If block"));
        }
        else{
            print(&utf8(b"Else block"));
        }; //if is an expression therefore it should be end with a semicolon.
    }
    
    #[test]
    fun testing()
    {
        control_flow();
    }
}
PreviousFunction VisibilitiesNextLoops

Last updated 2 years ago