Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialboris said
3,607 Pointswhen i try and do the loop it does this
//: Playground - noun: a place where people can play
import UIKit
var todo = ["Complete Laundry", "Take out bee nest", "Return Calls", "Get water", "Go to Bed"]
for useless in todo { println()
}
for number in 1...0 { println("(number) times 2 is (number*2)")
}
fatal error: Can't form Range with end < start Playground execution failed: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
- thread #1: tid = 0x46003, 0x000000010668352c libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 44, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
- frame #0: 0x000000010668352c libswiftCore.dylib
function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 44 frame #1: 0x000000010f5c3889 $__lldb_expr126
main + 2185 at For-in-Loop.playground:14 frame #2: 0x00000001047be710 For-in-Loop frame #3: 0x00000001047c25f1 For-in-Loopreabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) + 17 frame #4: 0x00000001047c11f1 For-in-Loop
partial apply forwarder for reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_owned (@in ()) -> (@out ()) + 81 frame #5: 0x00000001047c2620 For-in-Loopreabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> (@unowned ()) + 32 frame #6: 0x00000001047c2657 For-in-Loop
reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_unowned @objc_block () -> (@unowned ()) + 39 frame #7: 0x0000000104e0b41c CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 frame #8: 0x0000000104e01165 CoreFoundation
CFRunLoopDoBlocks + 341 frame #9: 0x0000000104e00923 CoreFoundation`CFRunLoopRun + 851 frame #10: 0x0000000104e00366 CoreFoundationCFRunLoopRunSpecific + 470 frame #11: 0x0000000104eae661 CoreFoundation
CFRunLoopRun + 97 frame #12: 0x00000001047bedc2 For-in-Loopmain + 1714 frame #13: 0x0000000107a99145 libdyld.dylib
start + 1 frame #14: 0x0000000107a99145 libdyld.dylib`start + 1
- frame #0: 0x000000010668352c libswiftCore.dylib
1 Answer
Jhoan Arango
14,575 PointsHello Boris :
I see what you are doing wrong here, I will point them out, and then give you the options to fix them. Please see the notes in green in the coding.
var todo = ["Complete Laundry", "Take out bee nest", "Return Calls", "Get water", "Go to Bed"]
for useless in todo {
println() // Give println something to print
}
for number in 1...0 { // Your rage is from 1 to 0 here
println("(number) times 2 is (number*2)") // String interpolation missing \
}
/*
If this was to work, it would print something like
1 times 2 is 0
1 times 2 is 0
1 times 2 is 0
This is why it does not work, your rage has to have a higher number.
*/
Here is how to fix that
var todo = ["Complete Laundry", "Take out bee nest", "Return Calls", "Get water", "Go to Bed"]
for useless in todo {
println(useless)
}
for number in 1...10 {
println("\(number) times 2 is \(number*2)")
}
Good luck.
boris said
3,607 Pointsboris said
3,607 Pointsfor some reason i named the constant useless