The 'with' scope function is a powerful tool in Kotlin that allows you to operate on an object without repeating its name. This is particularly useful when you need to perform multiple operations on the same object, making your code cleaner and more readable. It takes the object as a receiver and a block of code where you can access its properties and methods directly.
data class User(var name: String, var age: Int) fun main() { val user = User("Alice", 30) with(user) { println("User Name: $name") println("User Age: $age") age += 1 // Increment age } println("Updated Age: ${user.age}") }