We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Omitting Conditions from a for Loop in Go

Loops in Go can omit sections of a for loop. For example, the CONDITION (middle part) can be omitted which causes the loop to run forever.

for INITIAL; ; AFTER {
  // do something forever
}

Assignment

Complete the maxMessages function. The parameter thresh is your total budget in pennies. Return the maximum number of whole messages you can send without the total cost ever exceeding thresh.

Each message costs 100 pennies, plus an additional fee. The fee structure is:

  • 1st message: 100 + 0
  • 2nd message: 100 + 1
  • 3rd message: 100 + 2
  • 4th message: 100 + 3

Browser Freeze

If you lock up your browser by creating an infinite loop that isn't breaking, just click the cancel button.