// Created on savesnippets.com · https://savesnippets.com/rdnlz67IjVo3dX class UserController { // Initialized later (by DI framework, Android lifecycle, etc.) lateinit var userService: UserService fun init(svc: UserService) { userService = svc } fun isReady(): Boolean = ::userService.isInitialized // safe check fun doWork() { if (!isReady()) error("controller not initialized") // userService.greet(...) } } class UserService(val name: String) fun main() { // repeat — for-loop without an index name repeat(5) { println("hello $it") } val c = UserController() println(c.isReady()) // false c.init(UserService("alice")) println(c.isReady()) // true // Accessing uninitialized lateinit throws UninitializedPropertyAccessException }