Skip to content

Instantly share code, notes, and snippets.

@ShmuelMofrad
Created November 4, 2023 21:30
Show Gist options
  • Save ShmuelMofrad/82ac872e50728fd3e66dc8a590bcc6f9 to your computer and use it in GitHub Desktop.
Save ShmuelMofrad/82ac872e50728fd3e66dc8a590bcc6f9 to your computer and use it in GitHub Desktop.
Here is how you can write a for loop in Java, JavaScript, Rust, and Go

Java

// A for loop that prints the numbers from 1 to 10
for (int i = 1; i <= 10; i++) {
  System.out.println(i);
}

JavaScript

// A for loop that prints the numbers from 1 to 10
for (let i = 1; i <= 10; i++) {
  console.log(i);
}

Rust

// A for loop that prints the numbers from 1 to 10
for i in 1..=10 {
  println!("{}", i);
}

Go

// A for loop that prints the numbers from 1 to 10
for i := 1; i <= 10; i++ {
  fmt.Println(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment