Tags » Sabi

How to define a function in Swift without running it

Starting from the Simple C program found here on stackoverflow, I’ve done it again in Swift and here’s the code:

import Foundation

// variables and constants:

var dice1, dice2: UInt32
var score, scoreToWin, diceSum: Int
dice1 = 0
dice2 = 0
diceSum = 0

// functions:

func rollDice() ->Int {
  dice1 = arc4random() % 6 + 1
  dice2 = arc4random() % 6 + 1
  diceSum = Int(dice1 + dice2)
  println("\(diceSum)")
  return diceSum
}

// main:

score = rollDice()

println("\(dice1) \(dice2) \(score)")

switch score {
  case 7, 11:
    println("score=\(score)\nYou WIN")
  case 2, 3, 12:
    println("score=\(score)\nYou LOOSE")
  default:
    println("You have to roll a \(score) to WIN")
    do {
      scoreToWin = score
      diceSum = rollDice()
    if diceSum == 7 { println("You LOOSE") }
    else if diceSum == scoreToWin { println("You WIN") }
    } while (diceSum != scoreToWin && diceSum != 7)
}
… 63 more words
Recent Questions - Stack Overflow

Sabi ft. Oritse femi - Style

Download & Enjoy this New Hit from Artiste “Sabi” featuring “Oritse femi” and its titled “Style”… Check it Out and Share your Thoughts…

 

Music

Sabi – Style ft. Oriste Femi | @FoshoENT_Radio


Sabi, the newly signed artiste under JLWISE Music returns with the remix to his overwhelming, national hit “Show Your Style” featuring the Musical Taliban Oritse Femi and produced by LahLah, who’s responsible for most of OritseFemi’s hit songs.
34 more words

MUSIC

Music: Sabi – Style ft. Oritsefemi

abi, the newly signed artiste under JLWISE Music returns with the 50 more words

Music

MUSIC: YungBilo[@am_youngbillo] - U 2 Sabi

Nigeria based artist Benny Young Africa who recently got a deal with Bozza Music company in South Africa to market his music album Worldwide release his first single (BEAUTIFUL WOMAN) from his forth coming Album. 22 more words

Music