ખીલો ખોદતા ખાણ જો મળે ઝવેરાતની, તો નિરાંતે તારી ભક્તિ કરું શામળા | ભલું થયું ભાંગી જંજાળ, નવી નક્કોર દેશે શ્રીગોપાળ | જે તુજથી ના થઈ શકે એ જ કરાવ પ્રભુ પાસે, પાણિયારું પ્રભુ ભરશે નહિ ભરશે નદી તળાવ

Kiran Chauhan

Cogito, ergo sum // I think, therefore I am.

Learning Rust Pt. 6

—

Writing a condition is quite easy in Rust and follow simple and intuitive syntax and rule.

  1. No need to write the condition within bracket.
fn main() {
  let x = 4;
  
  if x % 2 == 0 {
    println!("{} is even.", x);
  }
}
  1. The expression must be evaluated to boolean value, otherwise, Rust will complain.
fn main() {
  let x = 4;
  
  if x {
    println!("{} is even.", x);
  }
}

As usual, we've the else with if.

fn main() {
  let x = 4;
  
  if x % 2 == 0 {
    println!("{} is even.", x);
  } else {
    println!("{} is odd.", x);
  }
}

Or you can even use else if in some specific scenario.

fn main() {
  let x = 4;
  
  if x > 0 {
    println!("{} is positive.", x);
  } else if x < 0 {
    println!("{} is negative.", x);
  } else {
    println!("{} must be zero.", x);
  }
}

સાહિત્યિક કાર્યક્રમો

  • તા. ૦૨-૧૮ ઓક્ટોબર ૨૦૨૬ - ગાંધી પુસ્તક મહોત્સવ, ગુજરાત વિદ્યાપીઠ, અમદાવાદ
  • તા. ૨૧-૨૫ ઓક્ટોબર ૨૦૨૬ - સંસ્કૃત વાગ્માધુરી ૨૦૨૬, રા. વિ. પાઠક સભાગૃહ, ગુજરાતી સાહિત્ય પરિસદ, આશ્રમ રોડ, અમદાવાદ.
  • તા. ૨૪–૨૫ ઓક્ટોબર ૨૦૨૬ - અમદાવાદ ઇન્ટરનેશનલ લિટરેચર ફેસ્ટિવલ
  • વધુ માહિતી માટે...

વર્ગીકૃત

કડીઓ

સૂચિત લેખો

ચોપડીઓ

જોયેલ